1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| from capstone import Cs from capstone import * import struct
def decode(offset,tmp): data_bin = open(r'E:\QQsavefile\MobileFile\mazes.exe', 'rb').read() data = data_bin[offset: offset+10921] md = Cs(CS_ARCH_X86, CS_MODE_64) inscnt = 0 inscnt2 = 0 map1 = [] map2 = [] map3 = [] for i in md.disasm(data, offset): ins = "0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str) if '\tmov\tdword ptr [rsp' in ins or '\tmov\teax, dword ptr [rip' in ins: if inscnt < 625: map1.append(int(i.op_str.split(', ')[1], 16)) inscnt += 1 elif inscnt2 < 2: map3.append(int(i.op_str.split(', ')[1], 16)) inscnt2 += 1 elif inscnt<629: off1 =i.address+int(i.op_str.split(', ')[1].split('+')[1].replace(']',''),16) map1_data = data_bin[0xa76098+tmp*5: 0xa76098+4+tmp*5 ] map1=map1+(list(map1_data)) inscnt+=4 if '\tlea\trcx, [rip' in ins: map2_data = data_bin[tmp*2512+0xa82610: tmp*2512+0xa82610+ 4 * 625] for i in range(625): map2.append(struct.unpack("I", map2_data[i * 4: i * 4 + 4])[0])
data = [] for i in range(625): data.append(map1[i] ^ map2[i]) return data, bytearray(map1[-4:]), map3
def checkValid(map, x, y): if x < 0 or y < 0 or x > 24 or y > 24: return False return map[y * 25 + x] == 0xd6
def solve(map, startX, startY, direct, path): map[startY * 25 + startX] = ord('*') if len(path) == 15: return True, path
all_dir = [] if checkValid(map, startX - 1, startY): all_dir.append((startX-1, startY, direct[0])) if checkValid(map, startX+ 1, startY ): all_dir.append((startX+ 1, startY , direct[1])) if checkValid(map, startX , startY- 1): all_dir.append((startX , startY- 1, direct[2])) if checkValid(map, startX, startY + 1): all_dir.append((startX, startY+1, direct[3]))
for dir in all_dir: result = solve(map, dir[0], dir[1], direct, path + dir[2]) if result[0] == True: return result return False, ''
def printMap(map1): for i in range(25): line = '' for j in range(25): line += chr(map1[i * 25 + j]) print(line)
total = '' tmp=0 for i in range(0,10933056+10944,10944): map1, dirs, target = decode(i+0x860,tmp) tmp+=1 total +=solve(map1, target[1], target[0], dirs.decode('utf-8'), '')[1]
import hashlib mm = hashlib.md5(total.encode('utf-8')).hexdigest() print(len(total)) print('nssctf{%s}' %mm)
|